/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phd.dupenois.changeidentifiers.dotpatterns;

import uk.co.dupenois.geometry.Coordinate;

/**
 *
 * @author mpd209
 */
public class Range {
    private Coordinate start;
    private Coordinate finish;
    private boolean allowCoincide;

    public Range(Coordinate start, Coordinate finish){
        this(start, finish, true);
    }

    public Range(Coordinate start, Coordinate finish, boolean allowCoincide){
        this.start = start;
        this.finish = finish;
        this.allowCoincide = allowCoincide;
    }

    public boolean in(Range range){
        if(!in(range.getStart())||!in(range.getFinish()))return false;
        return true;
    }

    public boolean in(Coordinate coord){
        if(isAllowCoincide()){
            if(coord.getX()<this.getStart().getX()||
                    coord.getX()>this.getFinish().getX()||
                    coord.getY()<this.getStart().getY()||
                    coord.getY()>this.getFinish().getY())return false;
        }else{
            if(coord.getX()<=this.getStart().getX()||
                    coord.getX()>=this.getFinish().getX()||
                    coord.getY()<=this.getStart().getY()||
                    coord.getY()>=this.getFinish().getY())return false;
        }
        return true;
    }

    public boolean overlap(Range range){
        if(in(range.getStart())&&!in(range.getFinish()))return true;
        if(!in(range.getStart())&&in(range.getFinish()))return true;
        return false;
    }

    /**
     * @return the start
     */
    public Coordinate getStart() {
        return start;
    }

    /**
     * @return the finish
     */
    public Coordinate getFinish() {
        return finish;
    }

    /**
     * @return the allowCoincide
     */
    public boolean isAllowCoincide() {
        return allowCoincide;
    }
}
